﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section Customer_Css{
    <link rel="stylesheet" href="@Url.Content("~/hplus/js/plugins/jquery-treegrid/css/jquery.treegrid.css")">
}
@functions{
    System.Text.StringBuilder sb = new System.Text.StringBuilder();
    public void GetMenuTr(MenuListModel model)
    {
        sb.Append(Html.Partial("View_MenuTrList", model).ToHtmlString());
        if (model != null && model.children.Count > 0)
        {
            foreach (var item in model.children)
            {
                GetMenuTr(item);
            }
        }
    }
}
@model List<MenuListModel>
<div class="row">
    <div class="panel panel-default">
        <div class="panel-body">
            <form class="form-inline" role="form" id="searchForm">
            @Html.Partial("UC_Button", ViewBag.ButtonList as List<Sys_Menu>)
            </form>
        </div>
    </div>
    <div class="panel panel-default">
        <div class="panel-body">
            <table id="flexigridData" class="table table-hover table-condensed table-striped table-bordered tree-grid">
                <thead>
                    <tr>
                        <th width="150">
                            菜单名称
                        </th>
                        <th width="150">
                            地址路径
                        </th>
                        <th width="120">
                            类型
                        </th>
                        <th width="100">
                            创建时间
                        </th>
                    </tr>
                </thead>
                <tbody>
                    @if (Model != null && Model.Count > 0)
                    {
                        foreach (var item in Model)
                        {
                            GetMenuTr(item);
                        }

                        @Html.Raw(sb.ToString());
                    }
                   
                </tbody>
            </table>
        </div>
    </div>
</div>
@section Customer_Js{
    <script type="text/javascript" src="@Url.Content("~/hplus/js/plugins/jquery-treegrid/js/jquery.treegrid.js")"></script>
    <script type="text/javascript">
        function addButton() {
            var $row = $('#flexigridData').find('tr.selected');
            var id = 0;
            var mentType = 0;
            if ($row.length > 0) {
                id = $row.attr('idField');
                menuType = $row.attr('menuType');
                window.location.href = '@Url.Action("AddButton", "Menu")?id=' + id + '&menuType=' + menuType;
            } else {
                window.location.href = '@Url.Action("AddButton", "Menu")';
            }
            return false;
        }

        function deleteMenu() {
            var $row = $('#flexigridData').find('tr.selected');
            var id = 0;
            if ($row.length > 0) {
                id = $row.attr('idField');
            } else {
                BootStrapUI_Core.alertError('请选择需要删除的行');
            }
            postAjax('@Url.Action("Delete", "Menu")', { id: id }, '是否确认删除');
            return false;
        }

        function editMenu() {
            var $row = $('#flexigridData').find('tr.selected');
            var id = 0;
            if ($row.length > 0) {
                id = $row.attr('idField');
                window.location.href = '@Url.Action("Edit", "Menu")?id=' + id;
            } else {
                BootStrapUI_Core.alertError('请选择需要编辑的行');
            }
            return false;
        }

        function addModular(){
            window.location.href = '@Url.Action("AddModular", "Menu")';
            return false;
        }

        function addNewMenu() {
            var $row = $('#flexigridData').find('tr.selected');
            var id = 0;
            var mentType=0;
            if ($row.length > 0) {
                id = $row.attr('idField');
                menuType = $row.attr('menuType');
                window.location.href = '@Url.Action("AddMenu", "Menu")?id=' + id + '&menuType=' + menuType;
            }else{
                window.location.href = '@Url.Action("AddMenu", "Menu")';
            }
            return false;
        }

        $(function () {
            $('#flexigridData').treegrid();

            $('#btnMenuAddButton').on('click', addButton);
            $('#btnMenuEdit').on('click', editMenu);
            $('#btnMenuDelete').on('click', deleteMenu);
            $("#btnMenuAddModular").on("click",addModular);
            $("#btnMenuAddMenu").on("click", addNewMenu);
        })
    </script>
}
